<%@ page contentType="text/html; charset=iso-8859-1" language="java" 
import="java.sql.*,data.*, java.util.ArrayList" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
<style type="text/css">
<!--
    .Table{
        background-color:#EDF6EA;
        border:1px solid #000000;
    }
    .button{
        background-color:#49743D;
        font-weight:bold;
        color:#ffffff;
    }
    .red {color: #FF0000}
    .noneDisplay{display: none;}
	.field{
		width : 80px;
	}
.style4 {font-size: medium}
-->
</style>
<script src="javascript/jquery.min.js"></script>
</head>

<body>
    <script>
        function setvalue(radio,field){
            var value = document.getElementById(radio).value;
            //alert(value);
            document.getElementById(field).value = value;
            $("#"+field).attr("readonly",true);
        }
        function doAll(target, field, err){
            $("#"+target).click(function(){
                setvalue(target,field);
                $("#"+err).fadeOut(1000);
            });
        }
        $(document).ready(function(){
            $("#spu").focusout(function(){
                var spu = document.getElementById("spu").value;
                //alert(spu);
                var int_spu = parseInt(spu);
                if(isNaN(int_spu)){
                    $("#errSPU").css("display","block");
                }else if(0 > int_spu){
                    $("#errSPU").text("Session_per_user cannot be negative!");
                }else{
                    $("#errSPU").fadeOut(1000);
                }
            });
            $("#ct").focusout(function(){
                var ct = document.getElementById("ct").value;
                //alert(spu);
                var int_ct = parseInt(ct);
                if(isNaN(int_ct)){
                    $("#errCT").css("display","block");
                }else if(0 > int_ct){
                    $("#errCT").text("Connect_time cannot be negative!");
                }else{
                    $("#errCT").fadeOut(1000);
                }
            });
            $("#it").focusout(function(){
                var it = document.getElementById("it").value;
                //alert(spu);
                var int_it = parseInt(it);
                if(isNaN(int_it)){
                    $("#errIT").css("display","block");
                }else if(0 > int_it){
                    $("#errSPU").text("Idle_time cannot be negative!");
                }else{
                    $("#errIT").fadeOut(1000);
                }
            });
            doAll("sesDef","spu","errSPU");
            doAll("sesUn","spu","errSPU");
            doAll("conDef","ct","errCT");
            doAll("conUn","ct","errCT");
            doAll("idlDef","it","errIT");
            doAll("idlUn","it","errIT");
        });
    </script>
<br />
<br />
<br />
<% 
	String name = request.getParameter("text");
	DataQuerry query = new DataQuerry();
	query.connectData(Constant.OracleAdminUsr, Constant.OracleAdminPwd);
	ArrayList<profileInfo> list = query.querryProfile();
	
	String SPU = "";
	String CT = "";
	String IT = "";
	for(int i = 0; i < list.size(); i++){
		if(list.get(i).getProfile().equals(name)){
			String resource = list.get(i).getResourceName();
			if(resource.equals("SESSIONS_PER_USER")){
				SPU = list.get(i).getLimit();
			}else if(resource.equals("CONNECT_TIME")){
				CT = list.get(i).getLimit();
			}else if(resource.equals("IDLE_TIME")){
				IT = list.get(i).getLimit();
			}
		}
	}
%>
<form id="form1" name="form1" method="post" action="profile_Modify">
<table width="386"  border="0" align="center" cellpadding="1" cellspacing="1" class = "Table">
  <tr>
    <td colspan="2"><div align="center"><strong>MODIFY PROFILE </strong></div></td>
  </tr>
  <tr>
    <td height="29"><strong>Name</strong></td>
    <td>
    <input class="field" name="name" type="text" id="name" value = "<%= name %>" readonly/>
     </td>
    </tr>
  <tr>
    <td width="118" height="29">
        <strong>Session_per_user</strong>    </td>
    <td>
      <input class="field" name="spu" type="text" id="spu" value = "<%= SPU %>" />
      <div id="errSPU" class ="red noneDisplay">Wrong type of Session_per_user(number only)</div>    
      <span class="style4">
      <%
      	String ses_check1 = "";
      	String ses_check2 = "";
      	if(SPU.equals("DEFAULT")){
      		ses_check1 = "checked = 'true'";
      	}else if(SPU.equals("UNLIMITED")){
      		ses_check2 = "checked = 'true'";
      	}
      %>
          <input id ="sesDef" name="session" type="radio" value ="DEFAULT" <%=ses_check1%> />
          Default
          <input id="sesUn" name="session" type="radio" value="UNLIMITED" <%=ses_check2%> />Unlimited
      </span>
    </td>
  </tr>
  <tr>
    <td height="28"><strong>Connect_time</strong></td>
    <td>
        <input class="field" name="ct" type="text" id="ct" value = "<%= CT %>" />
        <div id="errCT" class ="red noneDisplay">Wrong type of Connect_time(number only)</div>    
        <span class="style4">
        <%
      	String ct_check1 = "";
      	String ct_check2 = "";
      	if(CT.equals("DEFAULT")){
      		ct_check1 = "checked = 'true'";
      	}else if(CT.equals("UNLIMITED")){
      		ct_check2 = "checked = 'true'";
      	}
      	%>
            <input id="conDef" name="connect" type="radio" value ="DEFAULT" <%=ct_check1%>/>
            Default
            <input id="conUn" name="connect" type="radio" value="UNLIMITED" <%=ct_check2%>/>Unlimited
        </span>
    </td>
  </tr>
  <tr>
    <td height="27"><strong>Idle_time </strong></td>
    <td>
        <input class="field" name="it" type="text" id="it" value = "<%=IT%>" />
        <div id="errIT" class ="red noneDisplay">Wrong type of Idle_time(number only)</div>    
      <span class="style4">
      <%
      	String it_check1 = "";
      	String it_check2 = "";
      	if(SPU.equals("DEFAULT")){
      		it_check1 = "checked = 'true'";
      	}else if(SPU.equals("UNLIMITED")){
      		it_check2 = "checked = 'true'";
      	}
      %>
          <input id="idlDef" name="idle" type="radio" value ="DEFAULT" <%=it_check1%>/>
        Default
        <input id="idlUn" name="idle" type="radio" value="UNLIMITED" <%=it_check2%>/>Unlimited
      </span>
    </td>
  </tr>
  <tr>
    <td height="23" colspan="2" align="center" valign="middle" >
        <input type="submit" name="Submit" value="Submit" class ="button"/>    </td>
  </tr>
</table>
</form>
</body>
</html>
